import { request } from '@umijs/max';
import type { CurrentUser, GeographicItemType } from './data';

export async function queryCurrent(): Promise<{ data: CurrentUser }> {
  return request('/api/accountSettingCurrentUser');
}

export async function queryProvince(): Promise<{ data: GeographicItemType[] }> {
  return request('/api/geographic/province');
}

export async function queryCity(province: string): Promise<{ data: GeographicItemType[] }> {
  return request(`/api/geographic/city/${province}`);
}

export async function query() {
  return request('/api/users');
}

export async function getFilterOne(
  params: {
    id?: any;
    categoryId?: any;
    name?: any;
    value?: any;
  },
  options?: { [key: string]: any },
) {
  return request<{
    code: number;
    data: Record<string, any>;
    msg?: string;
  }>('/product-server/api/v1/filter/find', {
    params,
    ...(options || {}),
  });
}

export async function add(
  data: {
    id?: any;
    categoryId?: any;
    name?: any;
    value?: any;
  },
  options?: { [key: string]: any },
) {
  return request<{
    code: number;
    data: Record<string, any>;
    msg?: string;
  }>('/product-server/api/v1/filter/save', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}


export async function update(
  data: {
    id?: any;
    categoryId?: any;
    name?: any;
    value?: any;
  },
  options?: { [key: string]: any },
) {
  return request<{
    code: number;
    data: Record<string, any>;
    msg?: string;
  }>('/product-server/api/v1/filter/update', {
    method: 'PUT',
    data,
    ...(options || {}),
  });
}
